//加密解密
/**
 * @openapi
 * tags:
 * - name: crypto
 *   description: 加密解密
 */
const router = require("express-promise-router")();
const libCrypto=require('../../lib/lib_crypto');

//md5
/**
 * @openapi
 * /teacher/crypto/md5:
 *   post:
 *     tags:
 *     - crypto
 *     summary: 测试md5
 *     requestBody:
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               plainText:
 *                 type: string
 *       required: true
 *     responses:
 *       200:
 *         description: 返回md5处理的字符串
 */
router.post('/md5', async function(req, res) {
    const {plainText}=req.body;
    const md5Text=libCrypto.md5WithSalt(plainText);
    res.send(md5Text);
});

/**
 *
 * @openapi
 * /teacher/crypto/aesDecryptByKey:
 *   post:
 *     tags:
 *     - crypto
 *     summary: 解密
 *     requestBody:
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               sign:
 *                 type: string
 *               key:
 *                 type: string
 *       required: true
 *     responses:
 *       200:
 *         description: 返回解密的字符串
 */
//解密
router.post('/aesDecryptByKey', async function(req, res) {
    const {sign,key}=req.body;
    const plainText=libCrypto.aesDecryptByKey(sign,key);
    res.send(plainText);
});

module.exports = router;
